OLE.GETOBJECT Function
Syntax
Arguments
- ObjectName
The full path and name of the file containing the object to retrieve. If ObjectName is blank, ProgId is required.
- ProgId
A string representing the class of the object. If ObjectName is not null, ProgId is optional. The ProgId argument has the following syntax and parts: appname.objecttype
Description
Get an object by name from an OLE automation server.
Discussion
Uses an existing OLE automation object, if available. Otherwise, it creates a new one. The OLE.GETOBJECT() method returns a pointer to an existing OLE automation object, if available. Otherwise, it creates a new one. If ProgId is not specified, but ObjectName is, then the associated application is launched and a pointer to that application is returned. For example:
Dim CADObject As Object CADObject = GetObject("C:\CAD\SCHEMA.CAD")
When this code is executed, the application associated with the specified ObjectName is started and the object in the specified file is activated.
Example
Dim WB as P Dim OldText as C Dim NewText as C Dim I as N Dim CH as C NewText = "" WB = ole.getobject("","Word.Basic") WB.FileNew() WB.Insert("Ths iz pur splling fur sore!") WB.ToolsSpelling() WB.EditSelectAll() OldText = WB.selection() WB.FileExit(2) delete WB ui_dlg_box("Corrected","{text=50,5:oldtext}") ui_modeless_dlg_setfocus("corrected")
The following script returns the serial numbers of a computer's drives.
dim strComputer as C dim objWMIService as P dim colItems as P objWMIService = ole.GetObject("winmgmts:\\.\root\cimv2") colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") for each objItem in colItems ui_msg_box("Volume Serial Number for drive " + objItem.Name, objItem.VolumeSerialNumber) next
When using OLE with Microsoft Word, you must use the .QUIT() method to close the program.
dim x as P x = ole.GetObject("","word.application") ... x.application.quit()
Retrieving a Disk Serial Number
dim strComputer as C dim objWMIService as P dim colItems as P objWMIService = ole.GetObject("winmgmts:\\.\root\cimv2") colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") for each objItem in colItems ui_msg_box("Volume Serial Number for drive " + objItem.Name,objItem.VolumeSerialNumber) next
See Also